const path = require('path');

const HtmlWebpackPlugin = require('html-webpack-plugin');

module.exports = [{
    context: __dirname,
    entry: {
        app: './src/index.js'
    },
    output: {
        filename: '[name].js',
        path: path.resolve(__dirname, 'dist')
    },
    module: {
        unknownContextCritical : false,
        rules: [{
            test: /\.css$/,
            use: ['style-loader', 'css-loader']
        }, {
            test: /\.less$/,
            use: [{
                loader: 'style-loader' // creates style nodes from JS strings
            }, {
                loader: 'css-loader' // translates CSS into CommonJS
            }, {
                loader: 'less-loader' // compiles Less to CSS
            }]
        },
        {
            test: /\.(png|gif|jpg|jpeg|svg)$/,
            use: [{
                loader: 'file-loader',
                options: {
                    outputPath: 'images/'
                }
            }]
        },
        {
            test: /\.(gltf|bin|glb)$/,
            use: [{
                loader: 'file-loader',
                options: {
                    outputPath: 'model/'
                }
            }]
        },
        {
            test: /\.js$/, exclude: /node_modules/,
            loader: "babel-loader",
            // options: {
            //     presets: ['@babel/preset-env']
            // }
        }, {
            test: /\.(woff|woff2|eot|ttf|otf)$/,
            use: ['file-loader']
        }, {
            test: /\.worker\.js$/,
            use: { loader: 'worker-loader' }
        }, {
                test: /\.glsl$/,
                loader: 'webpack-glsl-loader'
            },
            {
                test: /\.(gltf|bin|glb)$/,
                use: [{
                    loader: 'file-loader',
                    options: {
                        outputPath: 'model/'
                    }
                }]
            },
        ]
    },
    plugins: [
        new HtmlWebpackPlugin({
            template: 'src/index.html'
        })
    ],
    // development server options
    devServer: {
        contentBase: path.join(__dirname, "dist"),
        host: '0.0.0.0',
    },
    devtool: 'source-map'
}];